File System Navigation Lab
1. Manage Files Using Command-Line Tools
In this lab, you practice efficient techniques for creating and organizing files using directories, file copies, and links.
Log in to your student account on
server1.example.com. Begin in yourhome directory.[student@server1 ~]$ cd ~
In your
home directory, create three subdirectories for organizing your files into classes. Call these directoriesMusic,Pictures, andVideos. Create all three with one command.[student@server1 ~]$ mkdir Music Pictures Videos [student@server1 ~]$ ls -l
In your
home directory, create sets of empty practice files to use for the remainder of this lab. If you don’t immediately recognize the intended command, use the guided solution to see and practice how the task is accomplished. Use the shell tab completion to locate and complete path names more easily.Create six files with names in the form
songX.mp3.Create six files with names in the form
snapX.jpg.Create six files with names in the form
filmX.avi.In each set, replace X with the numbers 1 through 6. [student@server1 ~]$ touch song1.mp3 song2.mp3 song3.mp3 song4.mp3 song5.mp3 song6.mp3 [student@server1 ~]$ touch snap1.jpg snap2.jpg snap3.jpg snap4.jpg snap5.jpg snap6.jpg [student@server1 ~]$ touch film1.avi film2.avi film3.avi film4.avi film5.avi film6.avi [student@server1 ~]$ ls -l
From your
home directory, move the song files into yourMusicsubdirectory, the snapshot files into yourPicturessubdirectory, and the movie files into yourVideossubdirectory.When distributing files from one location to many locations, first change to the directory containing the source files. Use the simplest path syntax, absolute or relative, to reach the destination for each file management task.
[student@server1 ~]$ mv song1.mp3 song2.mp3 song3.mp3 song4.mp3 song5.mp3 song6.mp3 Music [student@server1 ~]$ mv snap1.jpg snap2.jpg snap3.jpg snap4.jpg snap5.jpg snap6.jpg Pictures [student@server1 ~]$ mv film1.avi film2.avi film3.avi film4.avi film5.avi film6.avi Videos [student@server1 ~]$ ls -l Music Pictures Videos
In your
home directory, create three more subdirectories for organizing your files into projects. Call these directoriesfriends,family, andwork. Create all three with one command.You will use these directories to rearrange your files into projects.
[student@server1 ~]$ mkdir friends family work [student@server1 ~]$ ls -l
Collect some of the new files into the project directories for family and friends. Use as many commands as needed. You do not have to use only one command as in the example. For each project, first change to the project directory, then copy the source files into this directory. You are making copies, since you will keep the originals after giving these projects to family and friends.
Copy files (all types) containing numbers 1 and 2 to the
friendsfolder.Copy files (all types) containing numbers 3 and 4 to the
familyfolder.When collecting files from multiple locations into one location, change to the directory that will contain the destination files. Use the simplest path syntax, absolute or relative, to reach the source for each file management task. [student@server1 ~]$ cd friends [student@server1 friends]$ cp ~/Music/song1.mp3 ~/Music/song2.mp3 ~/Pictures/snap1.jpg ~/Pictures/snap2.jpg ~/Videos/film1.avi ~/Videos/film2.avi . [student@server1 friends]$ ls -l [student@server1 friends]$ cd ../family [student@server1 family]$ cp ~/Music/song3.mp3 ~/Music/song4.mp3 ~/Pictures/snap3.jpg ~/Pictures/snap4.jpg ~/Videos/film3.avi ~/Videos/film4.avi . [student@server1 family]$ ls -l
Create additional copies for your work project.
[student@server1 family]$ cd ../work [student@server1 work]$ cp ~/Music/song5.mp3 ~/Music/song6.mp3 ~/Pictures/snap5.jpg ~/Pictures/snap6.jpg ~/Videos/film5.avi ~/Videos/film6.avi . [student@server1 work]$ ls -l
Your projects are now done. To clean up the projects, change to your
home directoryand then attempt to delete both the family and friends projects with a singlermdircommand.[student@server1 work]$ cd [student@server1 ~]$ rmdir family friends rmdir:failed to remove 'family': Directory not empty rmdir:failed to remove 'friends': Directory not empty
Using the
rmdircommand should fail since both directories are non-empty.
Use another command that will succeed in deleting both the family and friends folders. You will be asked if you are sure that you wish to "descend into the directories" and "remove regular empty files", enter
yfor yes and then press Enter.[student@server1 ~]$ rm -r family friends [student@server1 ~]$ ls -l
You can avoid having to answer yes to all of those questions by adding the fflag to thermcommand to force the operation. For examplerm -rf family friendswould have removed all of the files and directories without asking. This can be dangerous so always use it carefully.Delete all the files in the work project, but do not delete the
workdirectory.[student@server1 ~]$ cd work [student@server1 work]$ rm -f song5.mp3 song6.mp3 snap5.jpg snap6.jpg film5.avi film6.avi [student@server1 work]$ ls -l
Finally, from your
home directory, use thermdircommand to delete theworkdirectory. The command should succeed now that it is empty.[student@server1 work]$ cd [student@server1 ~]$ rmdir work [student@server1 ~]$ ls -l
2. Make Links Between Files
In this lab, you create hard and soft links.
Log in to your
server1system as therootuser with the passwordr3dh@t1!.Create an additional hard link
/root/qmp-manual.txtand link it to the existing file/usr/share/doc/qemu-kvm/qmp-commands.txtonserver1.example.com.[root@server1 ~]# ln /usr/share/doc/qemu-kvm/qmp-commands.txt /root/qmp-manual.txt
Verify the link count on the newly created link
/root/qmp-manual.txt.[root@server1 ~]# ls -l /root/qmp-manual.txt -rw-r--r--. 2 root root 63889 Nov 11 02:8 /root/qmp-manual.txt
Verify the link count on the original file
/usr/share/doc/qemu-kvm/qmp-commands.txt.[root@server1 ~]# ls -l /usr/share/doc/qemu-kvm/qmp-commands.txt -rw-r--r--. 2 root root 63889 Nov 11 02:8 /usr/share/doc/qemu-kvm/qmp-commands.txt
Create the soft link
/root/tempdirand link it to/tmponserver1.example.com.[root@server1 ~]# ln -s /tmp /root/tempdir
Verify the newly created link with
ls -l.[root@server1 ~]# ls -l /root lrwxrwxrwx. 1 root root 4 Mar 13 08:2 /root/tempdir -> /tmp